package com.example.controller;

import com.example.common.aop.LogAnnotation;
import com.example.common.cache.Cache;
import com.example.service.ArticleService;
import com.example.vo.ArticleVo;
import com.example.vo.Result;
import com.example.vo.params.ArticleParam;
import com.example.vo.params.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//与json数据进行交互
@RestController
@RequestMapping("articles")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    //首页文章列表
    @PostMapping
    @LogAnnotation(module="文章",operator="获取文章列表")
    public Result listArticle(@RequestBody PageParams pageParams) {
        return articleService.listArticle(pageParams);
    }

    /**
     * 最热文章 根据观看量进行排序
     * @return
     */
    @PostMapping("hot")
    public Result hotArticle(){
        int limit=5;
        return articleService.hotArticle(limit);
    }

    /**
     * 最新文章
     * @return
     */

    //加缓存
    @Cache(expire = 1*60*1000,name = "new")
    @PostMapping("new")
    public  Result newArticle(){
        int limit=5;
        return articleService.newArticle(limit);
    }


    @PostMapping("listArchives") //
    public Result listArchives(){

        return articleService.listArchives();
    }

    @PostMapping("view/{id}")
    public Result findArticleById(@PathVariable("id") Long articleId){
        return articleService.findArticleById(articleId);
    }

    @PostMapping("publish")
    public Result publish(@RequestBody ArticleParam articleParam){
        return articleService.publish(articleParam);
    }

}
